Conversation
|
Also fixed Rails caching problems for Turbolinks 5 |
| def request_turbolinks_5_tureferrer? | ||
| defined?(request) && request.respond_to?(:headers) && request.headers["Turbolinks-Referrer"] | ||
| def is_turbolinks_5? | ||
| Gem::Version.new(Turbolinks::VERSION) >= Gem::Version.new('5.0.0') |
There was a problem hiding this comment.
Interesting approach. Question: what would happen if you have Turbolinks present in the project but not enabled in javascript ? I think in that case this solution will always return true
There was a problem hiding this comment.
Didn't cross my mind. Then i'm at my wit's end with this. I guess there is no way to determine if rails has loaded turbolinks.js with certainty.
My best bet is that it is only fixable by manually passing an argument that switches the turbolinks wrapper on/off
Anyhow. I guess i can't help on this one then.
Will keep using this for my implementation for the time being though.
There was a problem hiding this comment.
maybe a mix of the two solutions ?
is_turbolinks_5? && request_turbolinks_5_tureferrer?
There was a problem hiding this comment.
I agree with @michelson ... The solution that only checks the gem version causes problems when I'm rendering charts in a PDF, where I have JS enabled but Turbolinks is not enabled (it is on my application though)
There was a problem hiding this comment.
Well, my charts on PDFs are still not being rendered, don't know why... (they are rendered normally when using @michelsons master).
| document.addEventListener("turbolinks:load", function() { | ||
| document.addEventListener("turbolinks:load", function(e) { | ||
| #{core_js} | ||
| e.target.removeEventListener(e.type, arguments.callee); |
There was a problem hiding this comment.
interesting, can you explain to us what this code does. where is the arguments variable is defined ?
There was a problem hiding this comment.
The arguments.callee property contains the currently executing function. doc
you can always use:
var f = function(){ document.removeEventListener('turbolinks:load', f, true); #{core_js} }; document.addEventListener('turbolinks:load', f, true);
does the same thing.
There was a problem hiding this comment.
Any chance you can merge this fix without the rest of the PR? This fix is really important, but on the other hand other commits from this PR break my code (e.g. verifying how to encapsulate JS only based on the Turbolinks v5 gem being loaded into the application)
|
Hi @dredupuika , thanks for this PR submission. best |
|
What if we do it this way? |
|
@michelson did you have time to check this commit? |
I can confirm this works. @michelson would be nice to see this merged and released so we don't have to use a fork any longer. |
Remove event listener after it is executed